package com.caishi.lkx.exam.question;

import cn.hutool.core.collection.CollUtil;
import com.caishi.lkx.exam.model.QuestionModel;


import java.util.List;
import java.util.Map;

/**
 * 填空题
 */
public class FillDataProcess extends SubjectiveQuestionDataProcess<List<String>> {
    @Override
    protected double computedAnswerQualityLevel(QuestionModel questionModel) {
        //答案(5)： 填空题结构化4分，非结构化有答案2分，非结构化无答案0分
        List<Map<String, Object>> answers = questionModel.getQuOption();
        if (CollUtil.isNotEmpty(answers)) {
            boolean standard = answers.stream().allMatch(e -> e.get("pt") != null);
            if (standard) {
                return 4;
            } else {
                // 非结构化有答案2分
                return 2;
            }
        }
        return 0;
    }

    @Override
    protected double computedRightAnswerQualityLevel(QuestionModel questionModel) {
        //正确答案(10)： 主观题结构化的无答案8分，结构化有答案4分，非结构化答案2分，非结构化无答案0分
        Object obj = questionModel.getAnswer();
        if (obj instanceof List l && l.get(0) instanceof Map map) {
            List<Map<String, Object>> data = (List<Map<String, Object>>) map.get("vl");
            if (CollUtil.isNotEmpty(data)) {
                boolean standard = questionDataIsStandard(data);
                // 结构化有答案4分
                return standard ? 4 : 2;
            } else {
                // 结构化的无答案8分
                return 8;
            }
        }
        return 0;
    }

    @Override
    public boolean questionContentCheck(QuestionModel questionModel) {
        return super.questionContentCheck(questionModel) && CollUtil.isNotEmpty(questionModel.getQuOption());
    }
}
